package com.fulihui.wgj.schedule.job;

import com.alibaba.dubbo.config.annotation.Reference;
import com.fulihui.common.result.rpc.SimpleResult;
import com.fulihui.common.util.DateUtils;
import com.fulihui.wgj.facade.service.wx48.Wx48NewsInfoService;
import com.fulihui.wgj.schedule.annotation.MutexLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 微信48小时用户清理
 *
 * @author wang_wx
 * @date 2018-07-20
 */
@Component
public class Wx48HClearJob {

    private static final Logger LOGGER = LoggerFactory.getLogger(Wx48HClearJob.class);

    @Reference(version = "1.0.0")
    Wx48NewsInfoService wx48NewsInfoService;

    @MutexLock(node = "${job.node.wx48HClearJob_execute}")
    @Scheduled(cron = "${job.cron.wx48HClearJob_execute}")
    public void execute() {
        LOGGER.info("Wx48HClearJob start");
        SimpleResult<String> simpleResult = wx48NewsInfoService.deleteByLessModified(DateUtils.addHours(new Date(), -48));
        if (simpleResult.isSuccess()) {
            String count = simpleResult.getData();
            LOGGER.info("Wx48H Clear count = [{}]", count);
        }
        LOGGER.info("Wx48HClearJob end");
    }

}
